package com.ftwj.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.ftwj.entity.SchoolPlaceInfo;
import com.ftwj.entity.SchoolRoomInfo;
import com.ftwj.mapper.SchoolRoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.UUID;

@Service
public class SchoolRoomService {
    @Autowired
    private SchoolRoomMapper schoolRoomMapper;

    public IPage<Map<String ,Object>> selectSchoolRoomInfoByName(Page<Object> page,
                                                                  String name
    ){
        IPage<Map<String, Object>> schoolRoomList = schoolRoomMapper.selectSchoolRoomInfoByName(page,name);
        return schoolRoomList;
    }

    public int insertSchoolRoomInfo(SchoolRoomInfo schoolRoomInfo){
        if (schoolRoomInfo.getId() == null || schoolRoomInfo.getId().isEmpty()){
            String newId = UUID.randomUUID().toString();  // 生成UUID
            schoolRoomInfo.setId(newId);
            System.out.println("Generated UUID: " + newId);  // 输出生成的UUID
        }else {
            System.out.println("Using provided ID: " + schoolRoomInfo.getId());  // 输出提供的ID
        }
        return schoolRoomMapper.insertSchoolRoomInfo(schoolRoomInfo);
    }

    public int updateSchoolRoomInfo(SchoolRoomInfo schoolRoomInfo){
        return schoolRoomMapper.updateSchoolRoomInfo(schoolRoomInfo);
    }

    public int updateSchoolRoomOpenState(SchoolRoomInfo schoolRoomInfo){
        return schoolRoomMapper.updateSchoolRoomOpenState(schoolRoomInfo);
    }

    public int deleteSchoolRoomInfo(String id){
        return schoolRoomMapper.deleteSchoolRoomInfo(id);
    }

}
